#pragma once
#include"public_struct.h"
vector<double> averageOfLevels(TreeNode* root) {
	if (!root)return {};
	vector<double> result;
	queue<TreeNode*> q;
	q.push(root);
	while (!q.empty()) {
		int size = q.size();
		double sum = 0;
		for (int i = 0; i < size; ++i)
		{
			TreeNode* temp = q.front();
			q.pop();
			sum += temp->val;
			if (temp->left)q.push(temp->left);
			if (temp->right)q.push(temp->right);
		}
		result.push_back(sum / size);
	}
	return result;
}